package cn.itcast.hotel.web;

import cn.itcast.hotel.pojo.PageResult;
import cn.itcast.hotel.pojo.RequestParams;
import cn.itcast.hotel.service.IHotelService;
import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/hotel")
public class HotelController {


    @Resource
    private IHotelService hotelService;

    @PostMapping("/list")
    public PageResult search(@RequestBody Map<String,Object> params) {
        RequestParams requestParams = new RequestParams();
        String key = (String) params.get("key");
        Integer page = (Integer)params.get("page");
        Integer size = (Integer)params.get("size");
        String sortBy = (String) params.get("sortBy");
        String brand = (String) params.get("品牌");
        String star = (String) params.get("星级");
        Integer minPrice = (Integer) params.get("minPrice");
        Integer maxPrice = (Integer) params.get("maxPrice");
        String city = (String) params.get("城市");
        requestParams.setCity(city);
        requestParams.setKey(key);
        requestParams.setPage(page);
        requestParams.setSize(size);
        requestParams.setSortBy(sortBy);
        requestParams.setBrand(brand);
        requestParams.setMaxPrice(maxPrice);
        requestParams.setMinPrice(minPrice);
        requestParams.setStarName(star);
        System.out.println("requestParams:"+requestParams);
        return hotelService.search(requestParams);
    }

    @PostMapping("/filters")
    public Map<String, List<String>> filter(@RequestBody Map<String,Object> params) {

        RequestParams requestParams = new RequestParams();
        String key = (String) params.get("key");
        Integer page = (Integer)params.get("page");
        Integer size = (Integer)params.get("size");
        String sortBy = (String) params.get("sortBy");
        String city = (String) params.get("城市");
        String brand = (String) params.get("品牌");
        String star = (String) params.get("星级");
        Integer minPrice = (Integer) params.get("minPrice");
        Integer maxPrice = (Integer) params.get("maxPrice");
        requestParams.setKey(key);
        requestParams.setCity(city);
        requestParams.setPage(page);
        requestParams.setSize(size);
        requestParams.setSortBy(sortBy);
        requestParams.setBrand(brand);
        requestParams.setMaxPrice(maxPrice);
        requestParams.setMinPrice(minPrice);
        requestParams.setStarName(star);
        System.out.println("requestParams:"+requestParams);

        return hotelService.filters(requestParams);
    }

    @GetMapping("/suggestion")
    public List<String> getSuggestion( String key){
        return hotelService.getSuggestion(key);
    }
}
